<?php
    require_once('paths.inc');
    require_once('page.inc');
    require_once('utils.inc');
    require_once(INCLUDE_PATH.'constants.inc');

    session_start();
    select_language();

    if (isset($_GET['index'])) $index = $_GET['index'];
    if (isset($_GET['tip_cont'])) $tip_cont = $_GET['tip_cont'];

    for ($i = 0; $i < count($currencies); $i++)
        $monedaValues[] = $i;
	    
    if (isset($index)) {			                 
	    require_once(DB_PATH.'db.inc');    
        
	    $db = db_connect();
        if ($tip_cont == CT_CONT_CLIENT)
            $cont = $_SESSION['client']->conturi[$index];
	    else
            $cont = $_SESSION['firma']->conturi[$index];
	    $text = LANG_CONT_UPDATE;
	    $opt = "update";	
    }
    else {                                     
	    $text = LANG_CONT_CONFIRM; 
	    $opt = "insert";
	    $cont = new Cont(null, null, null, null,null, null);
    }

    if (!isset($index)) {
	    $cont->moneda = $_SESSION['user_logat']->moneda;
        $index = 0;      
    }
    
    $help_text = LANG_EXTRA_MODAL_ADD_CONT;
    if ($opt == "update")
        $help_text = LANG_EXTRA_MODAL_EDIT_CONT;
    
    echo "<div align=\"center\">";
	    echo '<table cellpadding="3" cellspacing="0" border="0" id="wrapper2">';
		    echo "<thead>";
			    echo "<tr>";
				    echo "<th colspan=\"2\">";
					    echo $text;
				    echo "</th>";
			    echo "</tr>";				
		    echo "</thead>";
		    echo '<tr class="capTabel">';
                echo '<td id="td_cont" align="right"><b>' . LANG_CONT . CT_OBLIGATORIU . '</b></td>';
                echo '<td align="left"><input type="text" value="' . $cont->cont . '" name="cont" id="cont" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />';
            echo '</tr>';
            echo '<tr class="capTabel">';
			    echo '<td id="td_moneda" align="right"><b>' . LANG_Moneda . '</b></td><td align="left">';
                render_combobox("moneda", $monedaValues, $currencies, $cont->moneda);
		    echo '</td></tr>';
		    
		    echo '<tr class="capTabel">';
			    echo '<td id="td_banca" align="right"><b>'.LANG_BANCA . CT_OBLIGATORIU .'</b></td>';
			    echo '<td align="left"><input type="text" value="' . $cont->banca . '" name="banca" id="banca" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />';
		    echo '</tr>';
		    echo '<tr class="capTabel">';
			    echo '<td id="td_sucursala" align="right"><b>'.LANG_SUCURSALA . CT_OBLIGATORIU . '</b></td>';
			    echo '<td align="left"><input type="text" value="' . $cont->sucursala . '" name="sucursala" id="sucursala" size="' . CT_MODAL_ADD_CONT_INPUT_SIZE_TEXT_BOX . '" />';
		    echo '</tr>';
		    echo '<tr class="capTabel">';
			    echo "<td colspan=\"2\" align=\"center\">";
				    echo '<input type="button" name="cont_confirm" id="cont_confirm" value="' . $text . '"' . "onclick=\"javascript: new_cont_confirm('" . $opt ."'," . $index . ", " . $tip_cont . ");\" />&nbsp;&nbsp;";
                    echo '<input type="button" name="cancel" value="'.LANG_CANCEL.'" onclick="javascript: closeMessage();" />';						
			    echo "</td>";
		    echo '</tr>';
            echo output_extra_text_modal($help_text, 2);
	    echo '</table>';
        
    echo "</div>";		
    flush();
?>